import { Modal } from "antd";
import ExcelSelectTable from "@/biz-components/excel-select-table";
import { xhrPostJson, xhrGet } from "@/services/index";
const SelectExcelModal = async (props: any) => {
  console.log('select excel modal 3', props)
  const title = props?.title || "选择";
  let dataSource
  if(props?.api) {
    const method = props?.api?.method || 'GET'
    let res:any = null
    if(method === 'GET') {
      res = await xhrGet(props.api.url, props.api.params)
    } else {
      res = await xhrPostJson(props.api.url, props.api.params)
    }
    dataSource = res.result
  } else if( props?.dataSource) {
    dataSource = props.dataSource
  } else {
    console.error('dataSource error')
  }

  // const dataSource = props?.dataSource || props?.dataSourceFunc?.() || [];
  let modal: any = null;
  const onRowClick = (code: any, name:any) => {
    props?.onOk(code, name);
    modal?.destroy();
  };

  let selectedKeys: any = [];
  const tableSelectCallback = (values: any[]) => {
    selectedKeys = values;
  };
  modal = Modal.confirm({
    title,
    content: (
      <ExcelSelectTable
        tableSelectCallback={tableSelectCallback}
        onRowClick={onRowClick}
        dataSource={dataSource}
        multiple={props?.multiple}
      />
    ),
    className: "model-excel-modal",
    okButtonProps: props?.multiple ? {} : { style: { display: "none" } },
    width: 600,
    onOk: () => {
      //   props?.onOk(selectedKeys);
    },
  });
};
export default SelectExcelModal